/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/15 17:37
  *
  * @file       hd_motor.h
  * @brief      Header file of Motor hardware driver.
  *
  * @note       This file contains the Xxx object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/15     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_HD_MOTOR_H
#define JLC_SKY_HD_MOTOR_H

#include "stm32f407xx.h"
#include "pd_timer_pwm.h"
#include "drivers.h"

typedef struct MotorDef Motor;

/**
 * This is a Motor that operated by TB6612 module.
 */
struct MotorDef {
    TimerPWM *timerPwm;  /* PWM signal input port */
    GPIO *in1GPIO;       /* AIN1 input port       */
    GPIO *in2GPIO;       /* AIN2 input port       */

    int8_t speed;               /* motor speed           */

    void (*init)(Motor *this);

    void (*start)(Motor *this);

    void (*stop)(Motor *this);

    void (*setSpeed)(Motor *this, int8_t speed);

};

extern const struct MotorClass {
    Motor *(*build)(TimerPWM *timerPwm, GPIO *in1GPIO, GPIO *in2GPIO);
} MotorBuilder;


#endif // JLC_SKY_HD_MOTOR_H
